package com.soft.javase.ch12.test.recursion;

/**
 * @author wangzhisen
 * @Desc TODO
 * @date 2025/5/14
 * 2.喝啤酒问题，一瓶啤酒2元，两个空瓶子可以换一瓶啤酒，四个啤酒盖可以换一瓶啤酒，请问10元共可以喝多少瓶？
 */
public class DrinkBeer {
    public static void main(String[] args) {
        int money = 10;
        int total = calculate(0, money / 2, money / 2);
        System.out.println("10元共可以喝" + total + "瓶啤酒");
    }

    private static int calculate(int sum, int bottles, int caps) {
        if (bottles < 2 && caps < 4) {
            return sum;
        }

        int newBeers = bottles / 2 + caps / 4;
        return calculate(
                sum + newBeers,
                bottles % 2 + newBeers,
                caps % 4 + newBeers
        );
    }
}
